package com.blueberry.quiz_master.chat.service;

import com.blueberry.quiz_master.chat.ai_app.ChatApp;
import com.blueberry.quiz_master.chat.model.ChatRequest;
import com.github.houbb.sensitive.word.bs.SensitiveWordBs;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;

import java.util.List;

@Service
public class ChatService {
    @Autowired
    private ChatApp chatApp;

    @Autowired
    private SensitiveWordBs sensitiveWordBs;

    public Flux<ChatResponse> StreamChat(ChatRequest chatRequest){
        List<String> foundWords = sensitiveWordBs.findAll(chatRequest.getUserQuestion());

        if(!foundWords.isEmpty()){
            String firstFoundWord = foundWords.get(0);
            throw new IllegalArgumentException("输入信息包含敏感词["+firstFoundWord+"]等，请修改后重试");
        }
        return chatApp.StreamChat(chatRequest);
    }
}
